<extend name="./Application/Admin/View/Layout/application.html"/>
<block name="css">
    <link rel="stylesheet" href="__PUBLIC__/assets/admin/css/common.css">
    <link rel="stylesheet" href="__PUBLIC__/vendor/nestable/jquery.nestable.css">
</block>

<block name="content">
    <div class="admin-content" id="app">

        <div class="am-cf am-padding">
            <div class="am-fl am-cf"><strong class="am-text-primary am-text-lg">编辑菜单与权限</strong> /
                <small>Create Menus & Rules</small>
            </div>
        </div>
        <hr>
        <div class="am-g">
            <div class="am-u-lg-6">
                <div class="am-panel-bd ">
                    <form class="am-form" data-am-validator>
                        <input type="hidden" name="id" value="{{$rul.id}}">
                        <div id="_method"></div>
                        <div class="am-g am-margin-top">
                            <div class="am-u-sm-4 am-u-md-3 am-text-right">
                                上级菜单
                            </div>
                            <div class="am-u-sm-8 am-u-md-9 am-u-end col-end">
                                <select name="parent_id" id="parent_id">
                                    <eq name="rul.parent_id" value="0">
                                        <option value="0">顶级菜单</option>
                                        <else/>
                                        <volist name="rules" id="rule">
                                            <option value="{{$rule.id}}"
                                            <eq name="rule.id" value="$rul.parent_id"> selected</eq>
                                            >

                                            {{$rule.title}}
                                            <volist name="rule['children']" id="children">

                                                <option value="{{$children.id}}"
                                                <eq name="children.id" value="$rul.parent_id">selected</eq>
                                                >
                                                &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;|--{{$children.title}}
                                                </option>

                                            </volist>
                                            </option>
                                        </volist>
                                    </eq>

                                </select>
                            </div>
                        </div>

                        <div class="am-g am-margin-top">
                            <div class="am-u-sm-4 am-u-md-3 am-text-right">
                                图标
                            </div>
                            <div class="am-u-sm-8 am-u-md-9">
                                <div class="am-form-group am-form-icon">
                                    <i class="permission.icon"></i>
                                    <input type="text" class="am-form-field am-input-sm" id="icon"
                                           value="{{$rul.icon}}">
                                </div>
                            </div>
                        </div>

                        <div class="am-g am-margin-top">
                            <div class="am-u-sm-4 am-u-md-3 am-text-right">
                                菜单名称
                            </div>
                            <div class="am-u-sm-8 am-u-md-9">
                                <input type="text" class="am-input-sm" id="title" value="{{$rul.title}}">
                            </div>
                        </div>

                        <div class="am-g am-margin-top">
                            <div class="am-u-sm-4 am-u-md-3 am-text-right">
                                权限名称
                            </div>
                            <div class="am-u-sm-8 am-u-md-9">
                                <textarea rows="4" id="name" placeholder="请输入权限名称" required>{{$rul.name}}</textarea>
                            </div>
                        </div>

                        <div class="am-margin">
                            <button type="submit" class="am-btn am-btn-primary am-radius submit">保 存</button>
                        </div>
                    </form>
                </div>
            </div>
        </div>

    </div>

</block>
<block name="js">
    <script src="__PUBLIC__/vendor/nestable/jquery.nestable.js"></script>
    <script>
        $(function () {
            $('.dd').nestable({
                maxDepth: 3,
            });

            //展开
            function expand() {
                $('.dd').nestable('expandAll');
            }

            //折叠
            function compress() {
                $('.dd').nestable('collapseAll');
            }

            //编辑菜单
            $('.submit').click(function () {
//                var input = $('input').serialize();
                var info = {
                    parent_id: $('#parent_id').val(),
                    icon: $('#icon').val(),
                    title: $('#title').val(),
                    name: $('#name').val(),
                    id: $('input:hidden').val(),
                }
//                console.log(info);
//                return false;
                $.ajax({
                    type: 'post',
                    url: "{{:U('edit_rule')}}",
                    data: info,
                    success: function (face) {
                        if (face.status == 1) {
                            alert(face.msg);
                            location.href = "{{:U('rule_manage')}}"
                        } else {
                            alert(face.msg);
                            return false;
                        }
                    }
                })
//                console.log(info);
                return false;
            })
            //删除一级权限菜单
//            $('.del_rule').click(function () {
//                var id = $(this).parents('li').data('id');
//                $.ajax({
//                    type: 'post',
//                    url: "{{:U('delete_rule')}}",
//                    data: {id: id},
//                    success: function (info) {
//                        if (info.status == 1) {
//                            alert(info.msg);
//                            $("li[data-id='" + id + "']").fadeOut(400);                        } else {
//                            alert(info.msg)
//                            return false;
//                        }
//
//                    }
//                })
//                return false;
//            })
            //删除二级菜单
//            $('.del_children').click(function () {
//                var _this = $(this)
//                var id = $(this).parents('li').data('id')
//                $.ajax({
//                    type: 'post',
//                    url: "{{:U('delete_children')}}",
//                    data: {id: id},
//                    success: function (info) {
//                        if (info.status == 1) {
//                            alert(info.msg);
//                            $("li[data-id='" + id + "']").fadeOut(400);
//                        } else {
//                            alert(info.msg);
//                            return false;
//                        }
//                    }
//                })
//                return false;
//            })

        })
    </script>
</block>